package prova;

public abstract class Robot {

	private String name;
	private double speed = 0;
	private double temperature = 0;
	private String status;
	private double power = 0;
	private double maxSpeed = 0;

	public double getMaxSpeed() {
		return maxSpeed;
	}

	public void setMaxSpeed(double maxSpeed) {
		this.maxSpeed = maxSpeed;
	}

	public Robot() {

	}

	public Robot(String name) {
		this.name = name;
	}

	public Robot(String name, double speed, double temperature, byte status, int power) {
		setName(name);
		setSpeed(speed);
		setTemperature(temperature);
		setStatus(status);
		setPower(power);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getSpeed() {
		return speed;
	}

	public void setSpeed(double speed) {
		double d = ((this.speed - speed) * 0.5) * -1;
		double e = getPower() - (getPower() * 0.1) * d;
		if (getTemperature() + d >= 0) {
			setTemperature(getTemperature() + d);
		} else {
			setTemperature(0);
		}
		if (e >= 0) {
			setPower(e);
		} else {
			setPower(0);
		}
		this.speed = speed;
	}

	public double getTemperature() {
		return temperature;
	}

	public void setTemperature(double temperature) {
		this.temperature = temperature;
	}

	public String getStatus() {
		return status;
	}

	protected void setStatus(byte status) {
		switch (status) {
		case 1:
			this.status = "standBy";
			break;
		case 2:
			this.status = "Moving";
			break;
		case 3:
			this.status = "Exploring";
			break;
		case 4:
			this.status = "Stopped";
			break;
		case 5:
			this.status = "returningHome";
			break;
		default:
			break;
		}

	}

	public double getPower() {
		return power;
	}

	public void setPower(double power) {
		if (power >= 0 && power <= 100) {
			this.power = power;
			if (power == 0) {
				standBy();
			}
		}
	}

	public void show() {
		System.out.println("Estado" + getStatus());
	}

	public void stop() {
		setSpeed(0);
		setStatus((byte) 4);
		setSpeed(0);
		if (getTemperature() > 0) {
			setTemperature(getTemperature() - getTemperature() * 0.1);
		}
	}

	private boolean getControleStatusSpeed() {
		return getStatus().equals("Moving") || getStatus().equals("Exploring") || getStatus().equals("returningHome");
	}

	public void speedUp(int vel) {
		if (getControleStatusSpeed()) {
			double d = getSpeed() + vel;
			if (d <= getMaxSpeed()) {
				setSpeed(d);
			} else {
				setSpeed(getMaxSpeed());
			}
		}
	}

	public void speedUp() {
		if (getControleStatusSpeed()) {
			double d = getSpeed() + getSpeed() * 0.1;
			if (d <= getMaxSpeed()) {
				setSpeed(d);
			} else {
				setSpeed(getMaxSpeed());
			}
		}
	}

	public void speedDown(int vel) {
		if (getControleStatusSpeed()) {
			double d = getSpeed() - vel;
			if (d >= 0) {
				setSpeed(d);
			} else {
				setSpeed(0);
			}
		}
	}

	public void speedDown() {
		if (getControleStatusSpeed()) {
			double d = getSpeed() - getSpeed() * 0.1;
			if (d >= 0) {
				setSpeed(d);
			} else {
				setSpeed(0);
			}
		}
	}

	public void standBy() {
		if (!getStatus().equals("standBy")) {
			setStatus((byte) 1);
			setSpeed(0);
			setTemperature(0);
		}
	}

	public void Explorer() {
		if (getStatus().equals("Stopped")) {
			setStatus((byte) 3);
			setTemperature(getTemperature() + 20);
			double d = getPower() - getPower() * 0.1;
			if (d >= 0) {
				setPower(d);
			} else {
				setPower(0);
			}
		}
	}

	public void returning() {
		if (getStatus().equals("Moving")) {
			setStatus((byte) 5);
		}
	}

	public void charge() {
		double d = getPower() + getPower() * 0.1;
		if (d <= 100) {
			setPower(d);
		} else {
			setPower(100);
		}
	}

	public void fullCharge() {
		setPower(100);
	}

}
